package com.wiscamp.ninechapters.problems.domain.models.types;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.wiscamp.ninechapters.problems.enums.QuestionModes;
import cube.ddd.domain.Entity;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 问题类型
 */
@Data
public class QuestionType implements Entity {
    /**
     * 题型编号
     */
    private long typeId = 0;

    /**
     * 题型代码
     */
    private String typeCode = "";

    /**
     * 题型名称
     */
    private String typeName = "";

    private int questionModeId;

    /**
     * 是否有高亮提示
     */
    private boolean hasHighlight = false;

    /**
     * 是否客观题
     */
    private boolean objectiveQuestion = true;

    /**
     * 是否有选项
     */
    private boolean hasOption = false;

    /**
     * 是否随机选项
     */
    private boolean randomOption = false;

    /**
     * 选项数量
     */
    private int optionQuantity = 0;

    /**
     * 答题描述
     */
    private String answerDescription = "";

    /**
     * 答题描述语音
     */
    private String answerDescriptionAudio = "";


    /**
     * 是否确认答题
     */
    private boolean confirmAnswer = false;

    /**
     * 答案是否排序
     */
    private boolean sortAnswer = false;

    /**
     * 答案是否分组
     */
    private boolean groupAnswer = false;

    private int solutionTypeId = 0;

    /**
     * 过期属性
     * 编辑器类型 1094-Multiple Choice 1095-Calculation
     * if the editor type is calculation , the answer type must be 'Number'.
     *
     * @deprecated 未来将使用questionMode判断编辑器类型
     */
    private int editorTypeId = 0;

    /**
     * 备注
     */
    private String remark = "";

    /**
     * 是否可用
     */
    private boolean enabled = true;

    /**
     * 是否删除
     */
    private boolean deleted = false;

    /**
     * 创建用户
     */
    private long creatorId = 0;

    /**
     * 创建时间
     */
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime creationTime;

    /**
     * 编辑用户
     */
    private long modifierId = 0;

    /**
     * 编辑时间
     */
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime modificationTime;

    private String questionModeName = "";

    private String solutionTypeName = "";

    private String creatorName = "";

    private String modifierName = "";

    public void enable() {
        if (!this.enabled) {
            this.enabled = true;
        }
    }

    public void disable() {
        if (this.enabled) {
            this.enabled = false;
        }
    }

    public void delete() {
        if (!this.deleted) {
            this.deleted = true;
        }
    }

    public void createBy(long operatorId) {
        this.creatorId = operatorId;
        this.creationTime = LocalDateTime.now();
        this.modifierId = operatorId;
        this.modificationTime = LocalDateTime.now();
    }

    public void updateBy(long operatorId) {
        this.modifierId = operatorId;
        this.modificationTime = LocalDateTime.now();
    }

    public QuestionModes getQuestionMode() {
        return QuestionModes.valueOf(this.questionModeId);
    }
}
